package listTest;

import java.util.LinkedList;

/**
 * @Author Zhang Chao
 * @Date 2021/5/17 9:01
 * @Version 1.0
 * 【6、使用链表实现栈效果】
 */

public class StackLTest {

    public static void main(String[] args) {
        StackL stackL = new StackL();
        for (int i = 0; i < 10 ; i++) {
            stackL.push(i);
        }
        System.out.println(stackL.top());
        System.out.println(stackL.top());
        System.out.println(stackL.pop());
        System.out.println(stackL.pop());
        System.out.println(stackL.pop());
    }

}
//使用链表封装好的栈
class StackL{
    private LinkedList<Object> list = new LinkedList<>();
    public void push(Object v){
        list.addFirst(v);
    }
    public Object top() {
        return list.getFirst();
    }
    public Object pop() {
        return list.removeFirst();
    }
}
